import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { NzMessageService }                                              from 'ng-zorro-antd';
import { _HttpClient }                                                   from '@delon/theme';
import { yuan }                                                          from '@shared';
import { DeviceService }                                                 from "../../device/device.service";
import { DeviceStatistics }                                              from "@shared/model/device-dto";

@Component({
    selector       : 'app-dashboard-analysis',
    templateUrl    : './analysis.component.html',
    styleUrls      : [ './analysis.component.less' ],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DashboardAnalysisComponent implements OnInit
{
    
    salesData: any;
    
    monthlyData: any[];
    rankingListData: any;
    deviceStatistics: DeviceStatistics;
    
    constructor(
        private http: _HttpClient,
        public msg: NzMessageService,
        private cdr: ChangeDetectorRef,
        private deviceSrv: DeviceService
    )
    {
    }
    
    ngOnInit()
    {
        this.http.get(`api/orders/statistics`).subscribe(value =>
        {
            this.salesData = value;
            this.monthlyData = [];
            value.monthlySales.forEach(item =>
            {
                this.monthlyData.push({ x: item.month, y: item.sales })
            });
            console.log(this.salesData);
            this.cdr.detectChanges()
        });
        
        this.http.get(`api/orders/store-ranking`).subscribe(value => this.rankingListData = value);
        
        this.deviceSrv.queryDeviceStatistics().subscribe(value => this.deviceStatistics = value)
    }
    
    setDate( type: any )
    {
    }
    
    changeSaleType()
    {
    }
    
    handlePieValueFormat( value: any )
    {
        return yuan(value);
    }
    
    salesChange( idx: number )
    {
    }
    
    offlineChange( idx: number )
    {
    }
}
